<!-- 搜索回车显示的歌手/专辑/歌单组件 -->
<template>
  <router-link to="">
    <div class="linkcover f-bd f-bd-btm" v-if="type == 0">
      <figure class="piccover">
        <img class="pic" :src="album[0].img1v1Url" alt="" />
      </figure>
      <article class="describe">
        <h4 class="maindes f-thide">
          歌手:
          <p class="hcover">
            <span v-html="keySign(album[0].name)"></span>
            <span v-html="album[0].alias[0] ? `(${keySign(album[0].alias[0])})` : ''"></span>
          </p>
        </h4>
      </article>
      <i class="u-svg u-svg-arr"></i>
    </div>
    <div class="linkcover f-bd f-bd-btm" v-else-if="type == 1">
      <figure class="piccover">
        <img class="pic" :src="album[0].blurPicUrl" alt="" />
      </figure>
      <article class="describe">
        <h4 class="maindes f-thide">
          专辑:
          <p class="hcover">
            <span v-html="keySign(album[0].name)"></span>
            <span v-html="album[0].alias[0] ? `(${keySign(album[0].alias[0])})` : ''"></span>
          </p>
        </h4>
        <p class="hcover addtional f-thide">
          <span v-html="keySign(singer(album[0].artists))"></span>
        </p>
      </article>
      <i class="u-svg u-svg-arr"></i>
    </div>
    <div class="linkcover f-bd f-bd-btm" v-else-if="type == 2">
      <figure class="piccover">
        <img class="pic" :src="album[0].coverImgUrl" alt="" />
      </figure>
      <article class="describe">
        <h4 class="maindes f-thide">
          歌单:
          <p class="hcover">
            <span v-html="keySign(album[0].name)"></span>
          </p>
        </h4>
        <p class="hcover addtional f-thide" v-html="'by ' + keySign(album[0].creator.nickname)"></p>
      </article>
      <i class="u-svg u-svg-arr"></i>
    </div>
  </router-link>
</template>

<script>
import { singer } from '@/utils/dedicated'
export default {
  props: {
    // 歌手/专辑/歌单数据
    album: {
      type: Array,
      default: () => [],
    },
    // 输入框的值
    type: {
      type: Number,
      default: 0,
    },
    //输入框的值
    values: {
      type: String,
      default: '',
    },
  },
  computed: {
    singer,
  },
  methods: {
    //选中字体变色
    keySign(val) {
      let s = this.values //关键字
      var str = val //将要修改的文本
      //去空格/用,隔开
      let inputvalue = s.replace(/\ +/g, ',') //把空格分开的字符串转换以逗号隔开
      let keyWordArr2 = inputvalue.split(',') //把字符串分割转换成数组
      //判断文本段落(原文本)是否为空
      if (str && str != '') {
        //遍历分割后的字符串
        keyWordArr2.forEach((e) => {
          let regStr = '' + `(${e})`
          let reg = new RegExp(regStr, 'g')
          //如果匹配成功则抛出关键字DOM
          str = str.replace(reg, '<span style="color:#507daf;">' + e + '</span>')
        })
      }
      return str
    },
  },
}
</script>

<style lang="scss" scoped>
.linkcover {
  display: flex;
  -webkit-box-align: center;
  align-items: center;
  height: 66px;
  margin-left: 10px;
  padding: 8px 10px 8px 0;
  box-sizing: border-box;
}
.f-bd {
  position: relative;
}
.f-bd:after {
  width: 200%;
  height: 200%;
  transform: scale(0.5);
  position: absolute;
  z-index: 2;
  content: '';
  top: 0;
  left: 0;
  pointer-events: none;
  box-sizing: border-box;
  transform-origin: top left;
  border: 0 solid rgba(0, 0, 0, 0.1);
}
.f-bd-btm:after {
  border-bottom-width: 1px;
}
.piccover {
  position: relative;
  width: 50px;
  height: 50px;
  margin: 0 15px 0 0;
  line-height: 0;
  flex: 0 0 auto;
  display: inline-block;
  .pic {
    display: block;
    width: 100%;
  }
}
.describe {
  -webkit-box-flex: 1;
  flex: 1;
  display: inline-block;
  width: 1%;
  .maindes {
    font-size: 17px;
    line-height: 30px;
    color: #333;
  }
  .hcover {
    display: inline;
  }
  .addtional {
    font-size: 12px;
    line-height: 15px;
    color: #999;
    width: 100%;
    display: inline-block;
  }
  h4 {
    margin: 0;
  }
  p {
    margin: 0;
  }
}
.f-thide {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
}
.u-svg-arr {
  margin-right: 8px;
  margin-left: 10px;
  flex: 0 0 auto;
  display: inline-block;
  width: 8px;
  height: 13px;
  background-image: url('../assets/img/v.svg');
}
.u-svg {
  vertical-align: middle;
  background-position: 0 0;
  background-size: contain;
  background-repeat: no-repeat;
}
h4 {
  font-weight: 400;
}
</style>